package raft

import (
	"fmt"
	"log"
)

// Debugging
const debug = 1

func logDebug(format string, a ...interface{}) (n int, err error) {
	if debug > 0 {
		log.Printf(format, a...)
	}
	return
}

func (rf *Raft) debug(format string, a ...interface{}) {
	if debug > 0 && !rf.killed() {
		message := fmt.Sprintf(format, a...)
		log.Printf("[%s %d/%d,i=%d,c=%d,a=%d] %s",
			rf.state,
			rf.me, rf.currentTerm,
			rf.log.appended,
			rf.log.committed,
			rf.log.applied,
			message,
		)
	}
}
